/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.portlet.editor.model.portlet.impl;

import java.rmi.server.UID;

import com.genia.toolbox.basics.i18n.I18nMessage;
import com.genia.toolbox.portlet.editor.model.portlet.PortletType;
import com.genia.toolbox.web.portlet.description.ContainerPortletDescription.LayoutDirection;

/**
 * The abstract portlet model.
 */
public class AbstractPortletModel
    implements PortletModel
{

  /**
   * The document unique ID.
   */
  private UID documentID = null;

  /**
   * The portlet unique ID.
   */
  private UID uniqueID = null;

  /**
   * The name.
   */
  private String name = null;

  /**
   * The portlet name.
   */
  private String portletName = null;

  /**
   * The description name.
   */
  private String descriptionName = null;

  /**
   * The description message.
   */
  private I18nMessage description = null;

  /**
   * The portlet identifier.
   */
  private String id = null;

  /**
   * The portlet type.
   */
  private PortletType type = null;

  /**
   * Whether the portlet is a sub-portlet.
   */
  private boolean isSubPortlet = false;

  /**
   * The parent direction.
   */
  private LayoutDirection parentDirection = null;

  /**
   * The parent unique ID.
   */
  private UID parentID = null;



  /**
   * Constructor.
   */
  public AbstractPortletModel()
  {
    super();
    this.uniqueID = new UID();
  }



  /**
   * Get the portlet description.
   * 
   * @return the portlet description.
   */
  public I18nMessage getDescription()
  {
    return this.description;
  }



  /**
   * Set the portlet description.
   * 
   * @param description
   *          the portlet description.
   */
  public void setDescription(I18nMessage description)
  {
    this.description = description;
  }



  /**
   * Get the portlet identifier.
   * 
   * @return the portlet identifier.
   */
  public String getId()
  {
    return this.id;
  }



  /**
   * Set the portlet identifier.
   * 
   * @param id
   *          the portlet identifier.
   */
  public void setId(String id)
  {
    this.id = id;
  }



  /**
   * Get the portlet name.
   * 
   * @return the portlet name.
   */
  public String getName()
  {
    return this.name;
  }



  /**
   * Set the portlet name.
   * 
   * @param name
   *          the portlet name.
   */
  public void setName(String name)
  {
    this.name = name;
  }



  /**
   * Get the portlet type.
   * 
   * @return the portlet type.
   */
  public PortletType getType()
  {
    return this.type;
  }



  /**
   * Set the portlet type.
   * 
   * @param type
   *          the portlet type.
   */
  public void setType(PortletType type)
  {
    this.type = type;
  }



  /**
   * Get the portlet unique ID.
   * 
   * @return the portlet unique ID.
   */
  public UID getUniqueID()
  {
    return this.uniqueID;
  }



  /**
   * Get the portlet name.
   * 
   * @return the portlet name.
   */
  public String getElementName()
  {
    return this.portletName;
  }



  /**
   * Set the portlet name.
   * 
   * @param portletName
   *          the portlet name.
   */
  public void setElementName(String portletName)
  {
    this.portletName = portletName;
  }



  /**
   * Get whether the portlet is a sub-portlet.
   * 
   * @return whether the portlet is a sub-portlet.
   */
  public boolean isSubElement()
  {
    return this.isSubPortlet;
  }



  /**
   * Set whether the portlet is a sub-portlet.
   * 
   * @param isSubPortlet
   *          whether the portlet is a sub-portlet.
   */
  public void setSubElement(boolean isSubPortlet)
  {
    this.isSubPortlet = isSubPortlet;
  }



  /**
   * Get the portlet parent unique ID.
   * 
   * @return the portlet parent unique ID.
   */
  public UID getParentID()
  {
    return this.parentID;
  }



  /**
   * Set the portlet parent unique ID.
   * 
   * @param parentID
   *          the portlet parent unique ID.
   */
  public void setParentID(UID parentID)
  {
    this.parentID = parentID;
  }



  /**
   * Get the document unique ID.
   * 
   * @return the document unique ID.
   */
  public UID getDocumentID()
  {
    return this.documentID;
  }



  /**
   * Set the document unique ID.
   * 
   * @param documentID
   *          the document unique ID.
   */
  public void setDocumentID(UID documentID)
  {
    this.documentID = documentID;
  }



  /**
   * Update a sub-portlet.
   * 
   * @param updatedPortlet
   *          the updated portlet.
   */
  public void updatePortlet(PortletModel updatedPortlet)
  {
    // Do nothing has there is no subportlet.
  }



  /**
   * Get the portlet description name.
   * 
   * @return the portlet description name.
   */
  public String getDescriptionName()
  {
    return this.descriptionName;
  }



  /**
   * Set the portlet description name.
   * 
   * @param descriptionName
   *          the portlet description name.
   */
  public void setDescriptionName(String descriptionName)
  {
    this.descriptionName = descriptionName;
  }



  /**
   * Get whether the settings are valid.
   * 
   * @return whether the settings are valid.
   */
  public boolean accept()
  {
    boolean isOK = true;
    if (this.getId() == null || this.getId().trim().length() == 0) {
      isOK = false;
    }
    return isOK;
  }



  /**
   * Get whether the portlet is a template (it contains at least one hole).
   * 
   * @return whether the portlet is a template.
   */
  public boolean isTemplate()
  {
    return false;
  }



  /**
   * Get the parent direction.
   * 
   * @return the parent direction.
   */
  public LayoutDirection getParentDirection()
  {
    return this.parentDirection;
  }



  /**
   * Set the parent direction.
   * 
   * @param parentDirection
   *          the parent direction.
   */
  public void setParentDirection(LayoutDirection parentDirection)
  {
    this.parentDirection = parentDirection;
  }



  /**
   * Get whether the element has at least one sub-element.
   * 
   * @return whether the element has at least one sub-element.
   */
  public boolean isContainer()
  {
    return false;
  }

}
